#include "QtUI/PackageInformationWidget.qth"
#include "QtUI/PackageInformationWidget.moh"
#include <QtGui/QLineEdit>
#include <QtGui/QTextEdit>
#include <QtGui/QGridLayout>
#include <QtGui/QLabel>
#include <QtGui/QRegExpValidator>


namespace QtUI
{

PackageInformationWidget::PackageInformationWidget( QWidget* pParent)
	: QWidget( pParent)
{
	QGridLayout* pLayout = new QGridLayout();
	this->setLayout( pLayout);

	pNameEditor_ = new QLineEdit();
	QLabel* pNameLabel = new QLabel();
	pNameLabel->setText( tr( "Name"));
	pNameLabel->setBuddy( pNameEditor_);
	pLayout->addWidget( pNameLabel, 0, 0);
	pLayout->addWidget( pNameEditor_, 0, 1);

	pDescriptionEditor_ = new QTextEdit();
	QLabel* pDescriptionLabel = new QLabel();
	pDescriptionLabel->setText( tr( "Description"));
	pDescriptionLabel->setBuddy( pDescriptionEditor_);
	pLayout->addWidget( pDescriptionLabel, 1, 0);
	pLayout->addWidget( pDescriptionEditor_, 1, 1);

	pNameValidator_ = new QRegExpValidator( QRegExp("[a-zA-Z]+([a-zA-Z0-9_\\s])*"), this);
	pNameEditor_->setValidator( pNameValidator_);

	pLayout->setAlignment( pDescriptionLabel, Qt::AlignLeft | Qt::AlignTop);
}

// ---------------------------------------------------------------------------------------------------------------------

QString PackageInformationWidget::packageName() const
{
	return pNameEditor_->text().trimmed();
}

// ---------------------------------------------------------------------------------------------------------------------

QString PackageInformationWidget::packageDescription() const
{
	return pDescriptionEditor_->toPlainText().trimmed();
}

// ---------------------------------------------------------------------------------------------------------------------

void PackageInformationWidget::setPackageName( const QString& newName)
{
	pNameEditor_->setText( newName);
}

// ---------------------------------------------------------------------------------------------------------------------

void PackageInformationWidget::setPackageDescription( const QString& newDescription)
{
	pDescriptionEditor_->setPlainText( newDescription);
}

} // namespace QtUI
